import Mock from 'mockjs'
const Qs = require('qs')
// const Random = Mock.Random
const labelList = [
  { id: 1, content: ['1', '11', 'hh', 'hahah'] },
  { id: 2, content: ['2', '22', 'hh', 'hahah'] },
  { id: 3, content: ['3', '33', 'hh', 'hahah'] }
]
// var labelList = []
// let user1 = {
//     id: 1,
//     content: ['1', '11', 'hh', 'hahah']
// }
// let user2 = {
//     id: 2,
//     content: ['2', '22', 'hh', 'hahah']
// }
// let user3 = {
//     id: 3,
//     content: ['3', '33', 'hh', 'hahah']
// }
// labelList.push(user1)
// labelList.push(user2)
// labelList.push(user3)

const getLabel = (params) => {
  console.log(params.body)
  return {
    data: labelList.find(e => String(e.id) === String(params.body))
      .content
  }
}

const addLabel = (params) => {
  let p = JSON.parse(Qs.parse(params).body)
  labelList.find(e => String(e.id) === String(p.id)).content.push(p.message)
  console.log(labelList)
  return '添加成功'
}
const delLabel = (params) => {
  let p = JSON.parse(Qs.parse(params).body)
  // var user =
  // var index = user.content.indexOf(p.message)
  // if (index > -1) {
  //     console.log(index)
  labelList.find(e => String(e.id) === String(p.id)).content.splice(labelList.find(e => String(e.id) === String(p.id)).content.indexOf(p.message), 1)
  return '删除成功'
}
Mock.mock('/api/getLabel', 'get', getLabel)
Mock.mock('/api/addLabel', 'post', addLabel)
Mock.mock('/api/delLabel', 'delete', delLabel)
